{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Load the required packages\n",
    "using ODE\n",
    "using JLD\n",
    "using ForwardDiff\n",
    "\n",
    "set_bigfloat_precision(113)\n",
    "\n",
    "# Define the system for the solver\n",
    "function vdpolAD(x)\n",
    "    return [x[2],((1-x[1]^2)*x[2]-x[1])*1e6]\n",
    "end\n",
    "\n",
    "function vdpol(t,x)\n",
    "    return vdpolAD(x)\n",
    "end\n",
    "\n",
    "function getJacobian(t,x)\n",
    "    J = Matrix{BigFloat}(2,2);\n",
    "    J[:,:] = ForwardDiff.jacobian(vdpolAD,x);\n",
    "    return J\n",
    "end\n",
    "\n",
    "# Set up the initial conditions\n",
    "tSpan = collect(zero(BigFloat):parse(BigFloat,\"11.0\"));\n",
    "x0 = [2*one(BigFloat),zero(BigFloat)];\n",
    "\n",
    "# Set the tolerances\n",
    "Tol = parse(BigFloat,\"1e-20\");\n",
    "\n",
    "# Solve and get the solution at T = tEnd\n",
    "(t,x_tmp) = ode23s(vdpol,x0,tSpan;\n",
    "reltol=Tol,abstol=Tol,points=:specified,\n",
    "jacobian = getJacobian);\n",
    "\n",
    "x_ref = Array{BigFloat}(11); \n",
    "\n",
    "for i=1:11\n",
    "    x_ref[i] = x_tmp[i+1,1][1];\n",
    "end\n",
    "\n",
    "# Save the solution to a file\n",
    "save(\"refSolVDPOL.jld\",\"x_ref\",x_ref);"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 0.4.2",
   "language": "julia",
   "name": "julia-0.4"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "0.4.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
